<template>
	<div>
		<el-form ref="form" :model="form" label-width="80px">
			<el-form-item label="姓名" prop="userName">
				<el-input v-model="form.userName"></el-input>
			</el-form-item>
			<el-form-item label="性别" prop="sex">
				<el-select v-model="form.sex" placeholder="请选择性别" clearable :style="{width: '100%'}">
					<el-option v-for="(item, index) in sexData" :key="index" :label="item.label" :value="item.value"
						:disabled="item.disabled"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="年龄" prop="age">
				<el-input v-model="form.age"></el-input>
			</el-form-item>
			<el-form-item label="就诊医院" prop="hospital">
				<el-input v-model="form.hospital"></el-input>
			</el-form-item>
			<el-form-item label="就诊科室" prop="historyOffice">
				<el-input v-model="form.historyOffice"></el-input>
			</el-form-item>
			<el-form-item label="就诊时间" prop="historyTime">
				<!-- <el-input v-model="form.historyTime"></el-input> -->
				<el-date-picker v-model="form.historyTime" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
					:style="{width: '100%'}" placeholder="请输入日期" clearable>
				</el-date-picker>
			</el-form-item>
			<el-form-item label="备注" prop="note">
				<el-input v-model="form.note"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="save">保存</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	export default {
		name: 'CaseHistoryEdit',
		components: {

		},
		props: ['editHistoryId'],
		data() {
			return {
				form: {
					userName: '',
					sex: '',
					age: '',
					hospital: '',
					historyOffice: '',
					historyTime: null,
					note: '',
				},
				sexData: [{
					"label": "男",
					"value": "男"
				}, {
					"label": "女",
					"value": "女"
				}],
				url: '/caseHistory/add'
			}
		},
		created() {
			console.log("this.editHistoryId:" + this.editHistoryId)
			if (this.editHistoryId) {
				this.url = '/caseHistory/update'
				this.axios.get('/caseHistory/toedit', resp => {
					this.form.historyId = resp.obj.historyId
					this.form.userName = resp.obj.userName
					this.form.sex = resp.obj.sex
					this.form.age = resp.obj.age
					this.form.hospital = resp.obj.hospital
					this.form.historyOffice = resp.obj.historyOffice
					this.form.historyTime = resp.obj.historyTime
					this.form.note = resp.obj.note
				}, {
					historyId: this.editHistoryId
				})
			}
		},
		methods: {
			save() {
				this.$refs['form'].validate((valid) => {
					if (valid) {
						this.axios.post(this.url, response => {
							// 子组件要改变父组件的值
							this.$emit('update:show', false)
							this.$emit('getData')
						}, this.form)
					}
				})
			}
		}
	}
</script>
<style>
</style>
